﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectCodeS.Models
{
    public class UserService : User
    {
        private ProjectCodeSContext db = new ProjectCodeSContext();
        public User GetUserByUsername(string username, string password)
        {
            User tempUser = db.Users.FirstOrDefault(user => user.Username == username && user.Password == password);
            return tempUser;
        }
        public User GetUserByUsername(string username)
        {
            User tempUser = db.Users.FirstOrDefault(user => user.Username == username);
            return tempUser;
        }
        public IEnumerable<User> GetAllUsers()
        {
            return db.Users.AsEnumerable();
        }
        public int RegisterUser(User user, string userrole)
        {
            User tempUser = new User();
            UserRoleService userRole = new UserRoleService();
            tempUser.Username = user.Username;
            tempUser.Password = user.Password;
            tempUser.UserEmailAddress = user.UserEmailAddress;
            tempUser.DateCreated = DateTime.Now;
            tempUser.LastUpdated = DateTime.Now;

            db.Users.Add(tempUser);
            db.SaveChanges();

            return tempUser.Id;
        }
    }
}